var local="http://47.104.10.151";
var keyId=getCookie('userId');
var de_id1;
var de_id2;
var de_id3;
var de_id4;
var de_id5;
var de_id6;
var de_id7;
var de_id8;
var de_id9;
var de_id10;

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}

function creatxmlHTTP() {
    if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlHttp=new XMLHttpRequest();
    }else {
        // IE6, IE5 浏览器执行代码
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    return xmlHttp;
}

function deletAdd1() {
    var delivery_id=de_id1;
    var add="";
    document.getElementById('message1').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    document.getElementById("ok1").style.visibility="hidden";
}
function deletAdd2() {
    var delivery_id=de_id2;
    var add="";
    document.getElementById('message2').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
  document.getElementById("ok2").style.visibility="hidden";
}
function deletAdd3() {
    var delivery_id=de_id3;
    var add="";
    document.getElementById('message3').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
  document.getElementById("ok3").style.visibility="hidden";
}
function deletAdd4() {
    var delivery_id=de_id4;
    var add="";
    document.getElementById('message4').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
  document.getElementById("ok4").style.visibility="hidden";
}
function deletAdd5() {
    var delivery_id=de_id5;
    var add="";
    document.getElementById('message5').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    document.getElementById("ok5").style.visibility="hidden";
}
function deletAdd6() {
    var delivery_id=de_id6;
    var add="";
    document.getElementById('message6').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
  document.getElementById("ok6").style.visibility="hidden";
}
function deletAdd7() {
    var delivery_id=de_id7;
    var add="";
    document.getElementById('message7').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
  document.getElementById("ok7").style.visibility="hidden";
}
function deletAdd8() {
    var delivery_id=de_id8;
    var add="";
    document.getElementById('message8').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
  document.getElementById("ok8").style.visibility="hidden";
}
function deletAdd9() {
    var delivery_id=de_id9;
    var add="";
    document.getElementById('message9').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
  document.getElementById("ok9").style.visibility="hidden";
}
function deletAdd10() {
    var delivery_id=de_id10;
    var add="";
    document.getElementById('message10').value=add;
    xmlHttp=creatxmlHTTP();
    var txt="";
    var url=local+":8080/delivery/deleteDelivery";
    txt="delivery_id="+delivery_id;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
  document.getElementById("ok10").style.visibility="hidden";
}


function findadd() {
    xmlHttp = creatxmlHTTP();
    var txt = "";//用于存储拼接字符串；
    var url = local+":8080/delivery/findDeliveryByUserId";
    //拼接字符
    txt = "user_id=" + keyId;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var result = xmlHttp.responseText;
            var json = eval("(" + result + ")");

            if(json.data[0].address!=null) {
                var add1 = "地址:" + json.data[0].address + "电话号码:" + json.data[0].phone;
                document.getElementById('message1').value=add1;
                de_id1=json.data[0].keyId;
            }

            if(json.data[1].address!=null) {
                var add2 = "地址:" + json.data[1].address + "电话号码:" + json.data[1].phone;
                document.getElementById('message2').value=add2;
                de_id2=json.data[1].keyId;
            }
            if(json.data[2].address!=null) {
                var add3 = "地址:" + json.data[2].address + "电话号码:" + json.data[2].phone;
                document.getElementById('message3').value=add3;
                de_id3=json.data[2].keyId;
            }
            if(json.data[3].address!=null) {
                var add4 = "地址:" + json.data[3].address + "电话号码:" + json.data[3].phone;
                document.getElementById('message4').value=add4;
                de_id4=json.data[3].keyId;
            }
            if(json.data[4].address!=null) {
                var add5 = "地址:" + json.data[4].address + "电话号码:" + json.data[4].phone;
                document.getElementById('message5').value=add5;
                de_id5=json.data[4].keyId;
            }
            if(json.data[5].address!=null) {
                var add6 = "地址:" + json.data[5].address + "电话号码:" + json.data[5].phone;
                document.getElementById('message6').value=add6;
                de_id6=json.data[5].keyId;
            }
            if(json.data[6].address!=null) {
                var add7 = "地址:" + json.data[6].address + "电话号码:" + json.data[6].phone;
                document.getElementById('message7').value=add7;
                de_id7=json.data[6].keyId;
            }
            if(json.data[7].address!=null) {
                var add8 = "地址:" + json.data[7].address + "电话号码:" + json.data[7].phone;
                document.getElementById('message8').value=add8;
                de_id8=json.data[7].keyId;
            }
            if(json.data[8].address!=null) {
                var add9 = "地址:" + json.data[8].address + "电话号码:" + json.data[8].phone;
                document.getElementById('message9').value=add9;
                de_id9=json.data[8].keyId;
            }
            if(json.data[9].address!=null) {
                var add10 = "地址:" + json.data[9].address + "电话号码:" + json.data[9].phone;
                document.getElementById('message10').value=add10;
                de_id10=json.data[9].keyId;
            }


        }
    }

}

function setDefaultDeliverly1() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id1;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
    document.getElementById("ok1").style.visibility="visible";
}
function setDefaultDeliverly2() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id2;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok2").style.visibility="visible";
}
function setDefaultDeliverly3() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id3;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok3").style.visibility="visible";
}
function setDefaultDeliverly4() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id4;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok4").style.visibility="visible";
}
function setDefaultDeliverly5() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id5;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok5").style.visibility="visible";

}
function setDefaultDeliverly6() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id6;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok6").style.visibility="visible";
}
function setDefaultDeliverly7() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id7;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok7").style.visibility="visible";
}
function setDefaultDeliverly8() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id8;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok8").style.visibility="visible";
}
function setDefaultDeliverly9() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id9;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok9").style.visibility="visible";
}
function setDefaultDeliverly10() {
    var url=local+":8080/delivery/setDefaultDelivery";
    var txt="user_id="+keyId+"&delivery_id="+de_id10;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    alert("设置成功");
  document.getElementById("ok10").style.visibility="visible";
}


